/**
 * 斗地主
 * @author Troj.an
 *
 */

class DDZGameEffectPanel extends PublicGameEffectPanel
{
    public txhight: any = -150;
    public zdhight: any = -250;


    public playShunzi(callback: () => void = null, thisObject: any = null): void {
        var ani = new how.Animator2();
        ani.horizontalCenter = 0;
        ani.verticalCenter = 0;//-250;
        ani.source = "shunzi";
        ani.sourceGroup = "ddz_effect";
        this.addChild(ani);
        ani.addEventListener(dragonBones.AnimationEvent.LOOP_COMPLETE, (event: dragonBones.AnimationEvent) => {
            event.currentTarget.parent.removeChild(event.currentTarget);
        }, this);
    }
    public playLiandui(callback: () => void = null, thisObject: any = null): void {
        var ani = new how.Animator2();
        ani.horizontalCenter = 0;
        ani.verticalCenter = 0;//-250;
        ani.source = "liandui";
        ani.sourceGroup = "ddz_effect";
        this.addChild(ani);
        ani.addEventListener(dragonBones.AnimationEvent.LOOP_COMPLETE, (event: dragonBones.AnimationEvent) => {
            event.currentTarget.parent.removeChild(event.currentTarget);
        }, this);
    }
    public playChuntian(callback: () => void = null, thisObject: any = null): void {
        var ani = new how.Animator2();
        ani.horizontalCenter = 0;
        ani.verticalCenter = 0;//-250;
        ani.source = "chuntian";
        ani.sourceGroup = "ddz_effect";
        this.addChild(ani);
        ani.addEventListener(dragonBones.AnimationEvent.LOOP_COMPLETE, (event: dragonBones.AnimationEvent) => {
            event.currentTarget.parent.removeChild(event.currentTarget);
            if (callback) {
                callback.call(this);
            }
        }, this);
    }
    public playFeiji(): void {
        var group = new eui.Group();
        this.addChild(group);
        group.verticalCenter = this.txhight//-150;
        var iconImg = new eui.Image();
        iconImg.source = "feijiEffect_png";
        var ani = new how.Animation2();
        ani.sourceGroup = "ddz_effect";
        ani.frameRate = 6;
        ani.nameReg = "feiji_\\d+_png";
        group.addChild(ani);
        group.addChild(iconImg);
        var layout = new eui.HorizontalLayout();
        group.layout = layout;
        layout.verticalAlign = "middle";
        layout.gap = 100;
        group.x = -504;
        egret.Tween.get(group).to({ x: this.stage.stageWidth }, 1200).call((g: eui.Group) => {
            this.removeChild(g);
        }, this, [group]);;
    }
    public playHuojian(): void {
        var ani = new how.Animator2();
        ani.horizontalCenter = 0;
        ani.verticalCenter = 0;//-250;
        ani.source = "huojian";
        ani.sourceGroup = "ddz_effect";
        this.addChild(ani);
        ani.addEventListener(dragonBones.AnimationEvent.LOOP_COMPLETE, (event: dragonBones.AnimationEvent) => {
            event.currentTarget.parent.removeChild(event.currentTarget);
        }, this);
    }
    public playZhadan(): void {
        var ani = new how.Animator2();
        ani.horizontalCenter = 0;
        ani.verticalCenter = 0;//-250;
        ani.source = "zhadan";
        ani.sourceGroup = "ddz_effect";
        this.addChild(ani);
        ani.addEventListener(dragonBones.AnimationEvent.LOOP_COMPLETE, (event: dragonBones.AnimationEvent) => {
            event.currentTarget.parent.removeChild(event.currentTarget);
        }, this);
    }
    public playMagicEffect(from: DDZPlayerView, to: DDZPlayerView, magicID: number): void {
        var magicNameConfig = {
            0: "dianzan",
            1: "jidan",
            2: "meigui",
            3: "zuzhou",
            4: "mofazhadan"
        };
        var group = new eui.Group();
        group.width = from.avatarImg.width;
        group.height = from.avatarImg.height;
        var fromGlobal = from.avatarImg.localToGlobal(0, 0);
        var fromLocal = this.globalToLocal(fromGlobal.x, fromGlobal.y);
        group.x = fromGlobal.x;
        group.y = fromGlobal.y;
        this.addChild(group);
        var ani = new how.Animation2();
        ani.sourceGroup = "ddz_effect";
        ani.nameReg = magicNameConfig[magicID] + "_\\d+_png";
        ani.autoPlay = false;
        ani.loop = false;
        ani.horizontalCenter = ani.verticalCenter = 0;
        ani.frameRate = 6;
        ani.visible = false;
        group.addChild(ani);
        var icon = new eui.Image();
        icon.source = magicNameConfig[magicID] + "_icon_png";
        icon.horizontalCenter = icon.verticalCenter = 0;
        group.addChild(icon);
        var toGlobal = to.avatarImg.localToGlobal(0, 0);
        var toLocal = this.globalToLocal(toGlobal.x, toGlobal.y);
        egret.Tween.get(group).to({ x: toLocal.x, y: toLocal.y }, 500).call((a: how.Animation2) => {
            a.visible = true;
            a.play();
            icon.visible = false;
        }, this, [ani]);
        ani.addEventListener(egret.Event.ENDED, (event: egret.Event) => {
            event.currentTarget.parent.parent.removeChild(event.currentTarget.parent);
        }, this);
    }

    public playLordCardEffect(point: egret.Point, texture: egret.Texture, index: number, cardData: string): void {
        var card: eui.Image = new eui.Image(texture);
        card.x = point.x;
        card.y = point.y;
        this.addChild(card);
        var gameView: DDZGameSceneView = how.Application.currentScene as DDZGameSceneView;
        var targetPoint = gameView.lordCardList.getElementAt(index).localToGlobal();
        targetPoint.x = targetPoint.x + gameView.lordCardList.scaleX * 70;
        targetPoint.y = targetPoint.y + gameView.lordCardList.scaleY * 93 - 20;
        egret.Tween.get(card).to({ x: targetPoint.x, y: targetPoint.y, scaleX: 0, scaleY: 0 }, 300).call((c: string, i: number) => {
            gameView.setLordCard(c, i);
        }, this, [cardData, index]);
    }
}